home *** CD-ROM | disk | FTP | other *** search
/ mail.altrad.com / 2015.02.mail.altrad.com.tar / mail.altrad.com / TEST / office german / PROPLUS.WW / PROPLSWW.CAB / MML2OMML.XSL < prev    next >
Extensible Markup Language  |  2006-08-27  |  64KB  |  1,727 lines

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:mml="http://www.w3.org/1998/Math/MathML"
  3.     xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math">
  4.     <xsl:output method="xml" encoding="UTF-8" />
  5.     
  6.     <!-- %%Template: match *
  7.  
  8.         The catch all template, just passes through 
  9.     -->
  10.     <xsl:template match="*">
  11.         <xsl:apply-templates select="*" />
  12.     </xsl:template>
  13.  
  14.     <!-- %%Template: match *
  15.  
  16.         Another catch all template, just passes through 
  17.     -->
  18.     <xsl:template match="/">
  19.         <m:oMath>
  20.             <xsl:apply-templates select="*" />
  21.         </m:oMath>
  22.     </xsl:template>
  23.  
  24.     <!-- %%Template: SReplace
  25.  
  26.         Replace all occurences of sOrig in sInput with sReplacement
  27.         and return the resulting string. -->
  28.     <xsl:template name="SReplace">
  29.         <xsl:param name="sInput" />
  30.         <xsl:param name="sOrig" />
  31.         <xsl:param name="sReplacement" />
  32.  
  33.         <xsl:choose>
  34.             <xsl:when test="not(contains($sInput, $sOrig))">
  35.                 <xsl:value-of select="$sInput" />
  36.             </xsl:when>
  37.             <xsl:otherwise>
  38.                 <xsl:variable name="sBefore" select="substring-before($sInput, $sOrig)" />
  39.                 <xsl:variable name="sAfter" select="substring-after($sInput, $sOrig)" />
  40.                 <xsl:variable name="sAfterProcessed">
  41.                     <xsl:call-template name="SReplace">
  42.                         <xsl:with-param name="sInput" select="$sAfter" />
  43.                         <xsl:with-param name="sOrig" select="$sOrig" />
  44.                         <xsl:with-param name="sReplacement" select="$sReplacement" />
  45.                     </xsl:call-template>
  46.                 </xsl:variable>
  47.  
  48.                 <xsl:value-of select="concat($sBefore, concat($sReplacement, $sAfterProcessed))" /> 
  49.             </xsl:otherwise>
  50.         </xsl:choose>
  51.     </xsl:template>
  52.  
  53.     <!-- %%Template: OutputText
  54.  
  55.         Post processing on the string given and otherwise do
  56.         a xsl:value-of on it -->
  57.     <xsl:template name="OutputText">
  58.         <xsl:param name="sInput" />
  59.  
  60.         <!-- Add local variable as you add new post processing tasks -->
  61.  
  62.         <!-- 1. Remove any unwanted characters -->
  63.         <xsl:variable name="sCharStrip">
  64.             <xsl:value-of select="translate($sInput, '⁢​', '')" />
  65.         </xsl:variable>
  66.  
  67.         <!-- 2. Replace any characters as needed -->
  68.         <!--    Replace ⩵ <-> ==             -->
  69.         <xsl:variable name="sCharReplace">
  70.             <xsl:call-template name="SReplace">
  71.                 <xsl:with-param name="sInput" select="$sCharStrip" />
  72.                 <xsl:with-param name="sOrig" select="'⩵'" />
  73.                 <xsl:with-param name="sReplacement" select="'=='" />
  74.             </xsl:call-template>
  75.         </xsl:variable>
  76.         
  77.         <!-- Finally, return the last value -->
  78.         <xsl:value-of select="$sCharReplace" />
  79.     </xsl:template>
  80.  
  81.     <!-- %%Template: mrow|mml:mstyle
  82.  
  83.          if this row is the next sibling of an n-ary (i.e. any of 
  84.          mover, munder, munderover, msupsub, msup, or msub with 
  85.          the base being an n-ary operator) then ignore this. Otherwise
  86.          pass through -->
  87.     <xsl:template match="mml:mrow|mml:mstyle">        
  88.         <xsl:choose>
  89.             <xsl:when test="preceding-sibling::*[1][self::mml:munder or self::mml:mover or self::mml:munderover or
  90.                                                     self::mml:msub or self::mml:msup or self::mml:msubsup]">
  91.                 <xsl:variable name="fNary">
  92.                     <xsl:call-template name="isNary">
  93.                         <xsl:with-param name="ndCur" select="preceding-sibling::*[1]/child::*[1]" />
  94.                     </xsl:call-template>
  95.                 </xsl:variable>
  96.                 <xsl:if test="not($fNary = 'true')">
  97.                     <xsl:apply-templates />
  98.                 </xsl:if>
  99.             </xsl:when>
  100.             <xsl:otherwise>
  101.                 <xsl:apply-templates />
  102.             </xsl:otherwise>
  103.         </xsl:choose>
  104.     </xsl:template>
  105.     <xsl:template match="mml:mi[not(child::mml:mglyph)] | 
  106.                          mml:mn[not(child::mml:mglyph)] | 
  107.                          mml:mo[not(child::mml:mglyph)] | 
  108.                          mml:ms[not(child::mml:mglyph)] | 
  109.                          mml:mtext[not(child::mml:mglyph)]">
  110.  
  111.         <!-- tokens with mglyphs as children are tranformed
  112.              in a different manner than "normal" token elements.  
  113.              Where normal token elements are token elements that
  114.              contain only text -->
  115.         <xsl:variable name="fStartOfRun" 
  116.                     select="count(preceding-sibling::*)=0 or
  117.                     preceding-sibling::*[1][not(self::mml:mi[not(child::mml:mglyph)]) and 
  118.                     not(self::mml:mn[not(child::mml:mglyph)]) and 
  119.                     not(self::mml:mo[not(child::mml:mglyph)]) and 
  120.                     not(self::mml:ms[not(child::mml:mglyph)]) and
  121.                     not(self::mml:mtext[not(child::mml:mglyph)])]" />
  122.  
  123.         <!--In MathML, successive characters that are all part of one string are sometimes listed as separate 
  124.             tags based on their type (identifier (mi), name (mn), operator (mo), quoted (ms), literal text (mtext)), 
  125.             where said tags act to link one another into one logical run.  In order to wrap the text of successive mi's, 
  126.             mn's, and mo's into one m:t, we need to denote where a run begins.  The beginning of a run is the first mi, mn, 
  127.             or mo whose immediately preceding sibling either doesn't exist or is something other than a "normal" mi, mn, mo, 
  128.             ms, or mtext tag-->
  129.         <xsl:variable name="fShouldCollect" 
  130.                     select="parent::mml:mrow or parent::mml:mstyle or 
  131.                     parent::mml:msqrt or parent::mml:menclose or
  132.                     parent::mml:math or parent::mml:mphantom or 
  133.                     parent::mml:mtd" />
  134.  
  135.         <!--In MathML, the meaning of the different parts that make up mathematical structures, such as a fraction 
  136.             having a numerator and a denominator, is determined by the relative order of those different parts.  
  137.             For instance, In a fraction, the numerator is the first child and the denominator is the second child.  
  138.             To allow for more complex structures, MathML allows one to link a group of mi, mn, and mo's together 
  139.             using the mrow, or mstyle tags.  The mi, mn, and mo's found within any of the above tags are considered 
  140.             one run.  Therefore, if the parent of any mi, mn, or mo is found to be an mrow or mstyle, then the contiguous 
  141.             mi, mn, and mo's will be considered one run.-->
  142.         <xsl:choose>
  143.             <xsl:when test="$fShouldCollect">
  144.                 <xsl:choose>
  145.                     <xsl:when test="$fStartOfRun">
  146.                         <!--If this is the beginning of the run, pass all run attributes to CreateRunWithSameProp.-->
  147.                         <xsl:call-template name="CreateRunWithSameProp">
  148.                             <xsl:with-param name="mathbackground" select="@mathbackground" />
  149.                             <xsl:with-param name="mathcolor" select="@mathcolor" />
  150.                             <xsl:with-param name="mathvariant" select="@mathvariant" />
  151.                             <xsl:with-param name="color" select="@color" />
  152.                             <xsl:with-param name="font-family" select="@font-family" />
  153.                             <xsl:with-param name="fontsize" select="@fontsize" />
  154.                             <xsl:with-param name="fontstyle" select="@fontstyle" />
  155.                             <xsl:with-param name="fontweight" select="@fontweight" />
  156.                             <xsl:with-param name="mathsize" select="@mathsize" />
  157.                             <xsl:with-param name="ndTokenFirst" select="." />
  158.                         </xsl:call-template>
  159.                     </xsl:when>
  160.                 </xsl:choose>
  161.             </xsl:when>
  162.             <xsl:otherwise>
  163.                 <!--Only one element will be part of run-->
  164.                 <xsl:element name="m:r">
  165.                     <!--Create Run Properties based on current node's attributes-->
  166.                     <xsl:call-template name="CreateRunProp">
  167.                         <xsl:with-param name="mathvariant" select="@mathvariant" />
  168.                         <xsl:with-param name="fontstyle" select="@fontstyle" />
  169.                         <xsl:with-param name="fontweight" select="@fontweight" />
  170.                         <xsl:with-param name="mathcolor" select="@mathcolor" />
  171.                         <xsl:with-param name="mathsize" select="@mathsize" />
  172.                         <xsl:with-param name="color" select="@color" />
  173.                         <xsl:with-param name="fontsize" select="@fontsize" />
  174.                         <xsl:with-param name="ndCur" select="." />
  175.                     </xsl:call-template>
  176.                     <xsl:element name="m:t">
  177.                         <xsl:call-template name="OutputText">
  178.                             <xsl:with-param name="sInput" select="normalize-space(.)" />
  179.                         </xsl:call-template>
  180.                     </xsl:element>
  181.                 </xsl:element>
  182.             </xsl:otherwise>
  183.         </xsl:choose>
  184.     </xsl:template>
  185.  
  186.     <!-- %%Template: CreateRunWithSameProp
  187.     -->
  188.     <xsl:template name="CreateRunWithSameProp">
  189.         <xsl:param name="mathbackground" />
  190.         <xsl:param name="mathcolor" />
  191.         <xsl:param name="mathvariant" />
  192.         <xsl:param name="color" />
  193.         <xsl:param name="font-family" />
  194.         <xsl:param name="fontsize" />
  195.         <xsl:param name="fontstyle" />
  196.         <xsl:param name="fontweight" />
  197.         <xsl:param name="mathsize" />
  198.         <xsl:param name="ndTokenFirst" />
  199.  
  200.         <!--Given mathcolor, color, mstyle's (ancestor) color, and precedence of 
  201.             said attributes, determine the actual color of the current run-->
  202.         <xsl:variable name="sColorPropCur">
  203.             <xsl:choose>
  204.                 <xsl:when test="$mathcolor!=''">
  205.                     <xsl:value-of select="$mathcolor" />
  206.                 </xsl:when>
  207.                 <xsl:when test="$color!=''">
  208.                     <xsl:value-of select="$color" />
  209.                 </xsl:when>
  210.                 <xsl:when test="$ndTokenFirst/ancestor::mml:mstyle[@color][1]/@color!=''">
  211.                     <xsl:value-of select="$ndTokenFirst/ancestor::mml:mstyle[@color][1]/@color" />
  212.                 </xsl:when>
  213.                 <xsl:otherwise>
  214.                     <xsl:value-of select="''" />
  215.                 </xsl:otherwise>
  216.             </xsl:choose>
  217.         </xsl:variable>
  218.  
  219.         <!--Given mathsize, and fontsize and precedence of said attributes, 
  220.             determine the actual font size of the current run-->
  221.         <xsl:variable name="sSzCur">
  222.             <xsl:choose>
  223.                 <xsl:when test="$mathsize!=''">
  224.                     <xsl:value-of select="$mathsize" />
  225.                 </xsl:when>
  226.                 <xsl:when test="$fontsize!=''">
  227.                     <xsl:value-of select="$fontsize" />
  228.                 </xsl:when>
  229.                 <xsl:otherwise>
  230.                     <xsl:value-of select="''" />
  231.                 </xsl:otherwise>
  232.             </xsl:choose>
  233.         </xsl:variable>
  234.  
  235.         <!--Given mathvariant, fontstyle, and fontweight, and precedence of 
  236.             the attributes, determine the actual font of the current run-->        
  237.         <xsl:variable name="sFontCur">
  238.             <xsl:call-template name="GetFontCur">
  239.                 <xsl:with-param name="mathvariant" select="$mathvariant" />
  240.                 <xsl:with-param name="fontstyle" select="$fontstyle" />
  241.                 <xsl:with-param name="fontweight" select="$fontstyle" />
  242.                 <xsl:with-param name="ndCur" select="$ndTokenFirst" />
  243.             </xsl:call-template>
  244.         </xsl:variable>
  245.  
  246.         <!--In order to determine the length of the run, we will find the number of nodes before the inital node in the run and
  247.             the number of nodes before the first node that DOES NOT belong to the current run.  The number of nodes that will
  248.             be printed is One Less than the difference between the latter and the former-->
  249.  
  250.         <!--Find index of current node-->
  251.         <xsl:variable name="nndBeforeFirst" select="count($ndTokenFirst/preceding-sibling::*)" />
  252.  
  253.         <!--Find index of next change in run properties-->
  254.         <xsl:variable name="nndBeforeLim" select="count($ndTokenFirst/following-sibling::*
  255.                     [(not(self::mml:mi) and not(self::mml:mn) and not(self::mml:mo) and not(self::mml:ms) and not(self::mml:mtext))
  256.                     or
  257.                     (self::mml:mi[child::mml:mglyph] or self::mml:mn[child::mml:mglyph] or self::mml:mo[child::mml:mglyph] or self::mml:ms[child::mml:mglyph] or self::mml:mtext[child::mml:mglyph])
  258.                     or 
  259.                     not(
  260.                         (($mathbackground=@mathbackground) or 
  261.                             ((not(@mathbackground) or $mathbackground) and (not($mathbackground) or $mathbackground=''))
  262.                         )
  263.                         and
  264.                         (($sColorPropCur=@mathcolor) or 
  265.                             ((not(@mathcolor) or @mathcolor='') and $sColorPropCur=@color) or
  266.                             ((not(@mathcolor) or @mathcolor='') and (not(@color) or @color='') and ancestor::mml:mstyle[@color][1]/@color=$sColorPropCur) or
  267.                             ((not(@mathcolor) or @mathcolor='') and (not(@color) or @color='') and (not(ancestor::mml:mstyle[@color][1]/@color) or ancestor::mml:mstyle[@color][1]/@color='') and (not($sColorPropCur) or $sColorPropCur=''))
  268.                         )
  269.                         and
  270.                         (($sSzCur=@mathsize) or
  271.                             ((not(@mathsize) or @mathsize='') and $sSzCur=@fontsize) or
  272.                             ((not(@mathsize) or @mathsize='') and (not(@fontsize) or @fontsize='') and (not($sSzCur) or $sSzCur=''))
  273.                         )
  274.                         and
  275.                         ((($sFontCur=@mathvariant) 
  276.                             or
  277.                             ((not(@mathvariant) or @mathvariant='') and ($sFontCur='normal') and (not(self::mml:mi)                                   or
  278.                                                                                                 (@fontstyle='normal' and (not(@fontweight='bold'))) or
  279.                                                                                                 (string-length(normalize-space(.)) > 1)
  280.                                                                                                 )) 
  281.                             or
  282.                             ((not(@mathvariant) or @mathvariant='') and ($sFontCur='bi') and (@fontstyle='italic' and @fontweight='bold')) 
  283.                             or
  284.                             (($sFontCur='italic') and (((not(@mathvariant) or @mathvariant='') and 
  285.                                                             (
  286.                                                             (@fontstyle='italic' and 
  287.                                                             (@fontweight='normal' or not(@fontweight) or @fontweight='')
  288.                                                             )
  289.                                                             or 
  290.                                                             ((not(@fontstyle) or @fontstyle='') and (not(@fontweight)=@fontweight=''))
  291.                                                             )
  292.                                                         ) or @mathvariant='italic'
  293.                                                         )
  294.                             ) 
  295.                             or
  296.                             (($sFontCur='bold') and (((not(@mathvariant) or @mathvariant='') and @fontweight='bold' and (@fontstyle='normal' or not(@fontstyle) or @fontstyle='')) or @mathvariant='bold')) 
  297.                             or
  298.                             (($sFontCur='' and (((not(@mathvariant) or @mathvariant='') and (not(@fontstyle) or @fontstyle='') and (not(@fontweight)or @fontweight='')) or 
  299.                                                     (@mathvariant='italic')                                      or 
  300.                                                     ((not(@mathvariant) or @mathvariant='') and @fontweight='normal' and @fontstyle='italic') or 
  301.                                                     ((not(@mathvariant) or @mathvariant='') and (not(@fontweight) or @fontweight='') and @fontstyle='italic')       or 
  302.                                                     ((not(@mathvariant) or @mathvariant='') and (not(@fontweight) or @fontweight='') and (not(@fontstyle) or @fontweight=''))
  303.                                                 )
  304.                             ))
  305.                             or
  306.                             ($sFontCur='normal' and 
  307.                             
  308.                             (self::mml:mi and 
  309.                             (not(@mathvariant) or @mathvariant='') and 
  310.                             (not(@fontstyle) or @fontstyle='') and
  311.                             (not(@fontweight) or @fontweight='') and 
  312.                             string-length(normalize-space(.)) > 1
  313.                             )
  314.                             or
  315.                             ( (self::mml:ms or self::mml:mtext) and
  316.                                 (not(@mathvariant) or @mathvariant='') and 
  317.                                 (not(@fontstyle) or @fontstyle) and
  318.                                 (not(@fontweight) or @fontweight)
  319.                             )
  320.                             )) 
  321.                             and not( (not(@mathvariant) or @mathvariant='') and 
  322.                                     (not(@fontstyle) or @fontstyle='') and
  323.                                     (not(@fontweight) or @fontweight='') and 
  324.                                     ((self::mml:mi and (string-length(normalize-space(.)) > 1)) or self::mml:ms or self::mml:mtext) and
  325.                                     ($sFontCur!='normal') )
  326.                         )
  327.                         and
  328.                         (($font-family=@font-family) or 
  329.                             ((not(@font-family) or @font-family) and (not($font-family) or $font-family=''))
  330.                         )
  331.                         )
  332.                     ][1]/preceding-sibling::*)" />
  333.  
  334.         <xsl:variable name="cndRun" select="$nndBeforeLim - $nndBeforeFirst" />
  335.  
  336.         <!--Contiguous groups of like-property mi, mn, and mo's are separated by non- mi, mn, mo tags, or mi,mn, or mo
  337.             tags with different properties.  nndBeforeLim is the number of nodes before the next tag which separates contiguous 
  338.             groups of like-property mi, mn, and mo's.  Knowing this delimiting tag allows for the aggregation of the correct 
  339.             number of mi, mn, and mo tags.-->
  340.         <xsl:element name="m:r">
  341.  
  342.             <!--The beginning and ending of the current run has been established. Now we should open a run element-->
  343.             <xsl:choose>
  344.  
  345.                     <!--If cndRun > 0, then there is a following diffrent prop, or non- Token, 
  346.                         although there may or may not have been a preceding different prop, or non-
  347.                         Token-->
  348.                 <xsl:when test="$cndRun > 0">
  349.                     <xsl:call-template name="CreateRunProp">
  350.                         <xsl:with-param name="mathvariant" select="$mathvariant" />
  351.                         <xsl:with-param name="fontstyle" select="$fontstyle" />
  352.                         <xsl:with-param name="fontweight" select="$fontweight" />
  353.                         <xsl:with-param name="mathcolor" select="$mathcolor" />
  354.                         <xsl:with-param name="mathsize" select="$mathsize" />
  355.                         <xsl:with-param name="color" select="$color" />
  356.                         <xsl:with-param name="fontsize" select="$fontsize" />
  357.                         <xsl:with-param name="ndCur" select="$ndTokenFirst" />
  358.                     </xsl:call-template>
  359.                     <xsl:element name="m:t">
  360.                         <xsl:call-template name="OutputText">
  361.                             <xsl:with-param name="sInput">
  362.                                 <xsl:choose>
  363.                                     <xsl:when test="namespace-uri($ndTokenFirst) = 'http://www.w3.org/1998/Math/MathML' and local-name($ndTokenFirst) = 'ms'">
  364.                                         <xsl:call-template name="OutputMs">
  365.                                             <xsl:with-param name="msCur" select="$ndTokenFirst" />
  366.                                         </xsl:call-template>
  367.                                     </xsl:when>
  368.                                     <xsl:otherwise>
  369.                                         <xsl:value-of select="normalize-space($ndTokenFirst)" />
  370.                                     </xsl:otherwise>
  371.                                 </xsl:choose>
  372.                                 <xsl:for-each select="$ndTokenFirst/following-sibling::*[position() < $cndRun]">
  373.                                     <xsl:choose>
  374.                                         <xsl:when test="namespace-uri(.) = 'http://www.w3.org/1998/Math/MathML' and 
  375.                                                     local-name(.) = 'ms'">
  376.                                             <xsl:call-template name="OutputMs">
  377.                                                 <xsl:with-param name="msCur" select="." />
  378.                                             </xsl:call-template>
  379.                                         </xsl:when>
  380.                                         <xsl:otherwise>
  381.                                             <xsl:value-of select="normalize-space(.)" />
  382.                                         </xsl:otherwise>
  383.                                     </xsl:choose>
  384.                                 </xsl:for-each>
  385.                             </xsl:with-param>
  386.                         </xsl:call-template>
  387.                     </xsl:element>
  388.                 </xsl:when>
  389.                 <xsl:otherwise>
  390.  
  391.                     <!--if cndRun lt;= 0, then iNextNonToken = 0, 
  392.                         and iPrecNonToken gt;= 0.  In either case, b/c there 
  393.                         is no next different property or non-Token 
  394.                         (which is implied by the nndBeforeLast being equal to 0) 
  395.                         you can put all the remaining mi, mn, and mo's into one 
  396.                         group.-->
  397.                     <xsl:call-template name="CreateRunProp">
  398.                         <xsl:with-param name="mathvariant" select="$mathvariant" />
  399.                         <xsl:with-param name="fontstyle" select="$fontstyle" />
  400.                         <xsl:with-param name="fontweight" select="$fontweight" />
  401.                         <xsl:with-param name="mathcolor" select="$mathcolor" />
  402.                         <xsl:with-param name="mathsize" select="$mathsize" />
  403.                         <xsl:with-param name="color" select="$color" />
  404.                         <xsl:with-param name="fontsize" select="$fontsize" />
  405.                         <xsl:with-param name="ndCur" select="$ndTokenFirst" />
  406.                     </xsl:call-template>
  407.                     <xsl:element name="m:t">
  408.  
  409.                         <!--Create the Run, first output current, then in a 
  410.                             for-each, because all the following siblings are
  411.                             mn, mi, and mo's that conform to the run's properties,
  412.                             group them together-->
  413.                         <xsl:call-template name="OutputText">
  414.                             <xsl:with-param name="sInput">
  415.                                 <xsl:choose>
  416.                                     <xsl:when test="namespace-uri($ndTokenFirst) = 'http://www.w3.org/1998/Math/MathML' and 
  417.                                                     local-name($ndTokenFirst) = 'ms'">
  418.                                         <xsl:call-template name="OutputMs">
  419.                                             <xsl:with-param name="msCur" select="$ndTokenFirst" />
  420.                                         </xsl:call-template>
  421.                                     </xsl:when>
  422.                                     <xsl:otherwise>
  423.                                         <xsl:value-of select="normalize-space($ndTokenFirst)" />
  424.                                     </xsl:otherwise>
  425.                                 </xsl:choose>
  426.                                 <xsl:for-each select="$ndTokenFirst/following-sibling::*[self::mml:mi or self::mml:mn or self::mml:mo or self::mml:ms or self::mml:mtext]">
  427.                                     <xsl:choose>
  428.                                         <xsl:when test="namespace-uri(.) = 'http://www.w3.org/1998/Math/MathML' and 
  429.                                                     local-name(.) = 'ms'">
  430.                                             <xsl:call-template name="OutputMs">
  431.                                                 <xsl:with-param name="msCur" select="." />
  432.                                             </xsl:call-template>
  433.                                         </xsl:when>
  434.                                         <xsl:otherwise>
  435.                                             <xsl:value-of select="normalize-space(.)" />
  436.                                         </xsl:otherwise>
  437.                                     </xsl:choose>
  438.                                 </xsl:for-each>
  439.                             </xsl:with-param>
  440.                         </xsl:call-template>
  441.                     </xsl:element>
  442.                 </xsl:otherwise>
  443.             </xsl:choose>
  444.         </xsl:element>
  445.  
  446.             <!--The run was terminated by an mi, mn, or mo with different properties, therefore,
  447.                 call-template CreateRunWithSameProp, using cndRun+1 node as new start node-->
  448.         <xsl:if test="$nndBeforeLim!=0 and 
  449.                     namespace-uri($ndTokenFirst/following-sibling::*[$cndRun])='http://www.w3.org/1998/Math/MathML' and
  450.                     (local-name($ndTokenFirst/following-sibling::*[$cndRun])='mi' or
  451.                     local-name($ndTokenFirst/following-sibling::*[$cndRun])='mn' or
  452.                     local-name($ndTokenFirst/following-sibling::*[$cndRun])='mo' or
  453.                     local-name($ndTokenFirst/following-sibling::*[$cndRun])='ms' or
  454.                     local-name($ndTokenFirst/following-sibling::*[$cndRun])='mtext') and
  455.                     (count($ndTokenFirst/following-sibling::*[$cndRun]/mml:mglyph) = 0)">
  456.             <xsl:call-template name="CreateRunWithSameProp">
  457.                 <xsl:with-param name="mathbackground" select="$ndTokenFirst/following-sibling::*[$cndRun]/@mathbackground" />
  458.                 <xsl:with-param name="mathcolor" select="$ndTokenFirst/following-sibling::*[$cndRun]/@mathcolor" />
  459.                 <xsl:with-param name="mathvariant" select="$ndTokenFirst/following-sibling::*[$cndRun]/@mathvariant" />
  460.                 <xsl:with-param name="color" select="$ndTokenFirst/following-sibling::*[$cndRun]/@color" />
  461.                 <xsl:with-param name="font-family" select="$ndTokenFirst/following-sibling::*[$cndRun]/@font-family" />
  462.                 <xsl:with-param name="fontsize" select="$ndTokenFirst/following-sibling::*[$cndRun]/@fontsize" />
  463.                 <xsl:with-param name="fontstyle" select="$ndTokenFirst/following-sibling::*[$cndRun]/@fontstyle" />
  464.                 <xsl:with-param name="fontweight" select="$ndTokenFirst/following-sibling::*[$cndRun]/@fontweight" />
  465.                 <xsl:with-param name="mathsize" select="$ndTokenFirst/following-sibling::*[$cndRun]/@mathsize" />
  466.                 <xsl:with-param name="ndTokenFirst" select="$ndTokenFirst/following-sibling::*[$cndRun]" />
  467.             </xsl:call-template>
  468.         </xsl:if>
  469.     </xsl:template>
  470.  
  471.     <!-- %%Template: CreateRunProp
  472.     -->
  473.     <xsl:template name="CreateRunProp">
  474.         <xsl:param name="mathbackground" />
  475.         <xsl:param name="mathcolor" />
  476.         <xsl:param name="mathvariant" />
  477.         <xsl:param name="color" />
  478.         <xsl:param name="font-family" />
  479.         <xsl:param name="fontsize" />
  480.         <xsl:param name="fontstyle" />
  481.         <xsl:param name="fontweight" />
  482.         <xsl:param name="mathsize" />
  483.         <xsl:param name="ndCur" />
  484.         <xsl:param name="fontfamily" />
  485.         <xsl:variable name="mstyleColor">
  486.             <xsl:if test="not(not($ndCur))">
  487.                 <xsl:value-of select="$ndCur/ancestor::mml:mstyle[@color][1]/@color" />
  488.             </xsl:if>
  489.         </xsl:variable>
  490.         <xsl:call-template name="CreateMathRPR">
  491.             <xsl:with-param name="mathvariant" select="$mathvariant" />
  492.             <xsl:with-param name="fontstyle" select="$fontstyle" />
  493.             <xsl:with-param name="fontweight" select="$fontweight" />
  494.             <xsl:with-param name="ndCur" select="$ndCur" />
  495.         </xsl:call-template>
  496.     </xsl:template>
  497.  
  498.     <!-- %%Template: CreateMathRPR
  499.     -->
  500.     <xsl:template name="CreateMathRPR">
  501.         <xsl:param name="mathvariant" />
  502.         <xsl:param name="fontstyle" />
  503.         <xsl:param name="fontweight" />
  504.         <xsl:param name="ndCur" />
  505.         <xsl:variable name="sFontCur">
  506.             <xsl:call-template name="GetFontCur">
  507.                 <xsl:with-param name="mathvariant" select="$mathvariant" />
  508.                 <xsl:with-param name="fontstyle" select="$fontstyle" />
  509.                 <xsl:with-param name="fontweight" select="$fontstyle" />
  510.                 <xsl:with-param name="ndCur" select="$ndCur" />
  511.             </xsl:call-template>
  512.         </xsl:variable>
  513.         <xsl:if test="$sFontCur!='italic' and $sFontCur!=''">
  514.             <xsl:call-template name="CreateMathScrStyProp">
  515.                 <xsl:with-param name="font" select="$sFontCur" />
  516.             </xsl:call-template>
  517.         </xsl:if>
  518.     </xsl:template>
  519.  
  520.     <!-- %%Template: GetFontCur
  521.     -->
  522.     <xsl:template name="GetFontCur">
  523.         <xsl:param name="ndCur" />
  524.         <xsl:param name="mathvariant" />
  525.         <xsl:param name="fontstyle" />
  526.         <xsl:param name="fontweight" />
  527.         <xsl:choose>
  528.             <xsl:when test="$mathvariant!=''">
  529.                 <xsl:value-of select="$mathvariant" />
  530.             </xsl:when>
  531.             <xsl:when test="not($ndCur)">
  532.                 <xsl:value-of select="'italic'" />
  533.             </xsl:when>
  534.             <xsl:when test="local-name($ndCur)='mi' and namespace-uri(.)='http://www.w3.org/1998/Math/MathML' and (string-length(normalize-space($ndCur))) <= 1">
  535.  
  536.                 <!--Default is fontweight = 'normal' and fontstyle='italic'
  537.                     In MathML if the string-length of the contents of an mi tag is =1, then the font 
  538.                     of the contents is italics, however, if the length is >1, then the font is plain.  
  539.                     This test considers the latter case.-->
  540.                 <xsl:choose>
  541.                     <xsl:when test="$fontstyle='normal' and $fontweight='bold'">
  542.                         <xsl:value-of select="'bold'" />
  543.                     </xsl:when>
  544.                     <xsl:when test="$fontstyle='normal'">
  545.                         <xsl:value-of select="'normal'" />
  546.                     </xsl:when>
  547.                     <xsl:when test="$fontstyle='bold'">
  548.                         <xsl:value-of select="'bi'" />
  549.                     </xsl:when>
  550.                     <xsl:otherwise>
  551.                         <xsl:value-of select="'italic'" />
  552.                     </xsl:otherwise>
  553.                 </xsl:choose>
  554.             </xsl:when>
  555.             <xsl:when test="local-name($ndCur)='mn' and namespace-uri(.)='http://www.w3.org/1998/Math/MathML' and string(number($ndCur/text()))!='NaN'">
  556.                 <xsl:value-of select="string(number($ndCur/text()))" />
  557.  
  558.                 <!--Default is fontweight = 'normal' and fontstyle='italic'-->
  559.                 <xsl:choose>
  560.                     <xsl:when test="$fontstyle='normal' and $fontweight='bold'">
  561.                         <xsl:value-of select="'bold'" />
  562.                     </xsl:when>
  563.                     <xsl:when test="$fontstyle='normal'">
  564.                         <xsl:value-of select="'normal'" />
  565.                     </xsl:when>
  566.                     <xsl:when test="$fontstyle='bold'">
  567.                         <xsl:value-of select="'bi'" />
  568.                     </xsl:when>
  569.                     <xsl:otherwise>
  570.                         <xsl:value-of select="'italic'" />
  571.                     </xsl:otherwise>
  572.                 </xsl:choose>
  573.             </xsl:when>
  574.             <xsl:otherwise>
  575.  
  576.                 <!--Default is fontweight = 'normal' and fontstyle='normal'-->
  577.                 <xsl:choose>
  578.                     <xsl:when test="$fontstyle='italic' and $fontweight='bold'">
  579.                         <xsl:value-of select="'bi'" />
  580.                     </xsl:when>
  581.                     <xsl:when test="$fontstyle='italic'">
  582.                         <xsl:value-of select="'italic'" />
  583.                     </xsl:when>
  584.                     <xsl:when test="$fontstyle='bold'">
  585.                         <xsl:value-of select="'bold'" />
  586.                     </xsl:when>
  587.                     <xsl:otherwise>
  588.                         <xsl:value-of select="'normal'" />
  589.                     </xsl:otherwise>
  590.                 </xsl:choose>
  591.             </xsl:otherwise>
  592.         </xsl:choose>
  593.     </xsl:template>
  594.  
  595.     <!-- %%Template: CreateMathScrStyProp
  596.     -->
  597.     <xsl:template name="CreateMathScrStyProp">
  598.         <xsl:param name="font" />
  599.         <xsl:element name="m:rPr">
  600.             <xsl:choose>
  601.                 <xsl:when test="$font='normal'">
  602.                     <xsl:element name="m:sty">
  603.                         <xsl:attribute name="m:val">p</xsl:attribute>
  604.                     </xsl:element>
  605.                 </xsl:when>
  606.                 <xsl:when test="$font='bold'">
  607.                     <xsl:element name="m:sty">
  608.                         <xsl:attribute name="m:val">b</xsl:attribute>
  609.                     </xsl:element>
  610.                 </xsl:when>
  611.                 <xsl:when test="$font='italic'">
  612.                 </xsl:when>
  613.                 <xsl:when test="$font='script'">
  614.                     <xsl:element name="m:scr">
  615.                         <xsl:attribute name="m:val">script</xsl:attribute>
  616.                     </xsl:element>
  617.                 </xsl:when>
  618.                 <xsl:when test="$font='bold-script'">
  619.                     <xsl:element name="m:scr">
  620.                         <xsl:attribute name="m:val">script</xsl:attribute>
  621.                     </xsl:element>
  622.                     <xsl:element name="m:sty">
  623.                         <xsl:attribute name="m:val">b</xsl:attribute>
  624.                     </xsl:element>
  625.                 </xsl:when>
  626.                 <xsl:when test="$font='double-struck'">
  627.                     <xsl:element name="m:scr">
  628.                         <xsl:attribute name="m:val">double-struck</xsl:attribute>
  629.                     </xsl:element>
  630.                     <xsl:element name="m:sty">
  631.                         <xsl:attribute name="m:val">p</xsl:attribute>
  632.                     </xsl:element>
  633.                 </xsl:when>
  634.                 <xsl:when test="$font='fraktur'">
  635.                     <xsl:element name="m:scr">
  636.                         <xsl:attribute name="m:val">fraktur</xsl:attribute>
  637.                     </xsl:element>
  638.                     <xsl:element name="m:sty">
  639.                         <xsl:attribute name="m:val">p</xsl:attribute>
  640.                     </xsl:element>
  641.                 </xsl:when>
  642.                 <xsl:when test="$font='bold-fraktur'">
  643.                     <xsl:element name="m:scr">
  644.                         <xsl:attribute name="m:val">fraktur</xsl:attribute>
  645.                     </xsl:element>
  646.                     <xsl:element name="m:sty">
  647.                         <xsl:attribute name="m:val">b</xsl:attribute>
  648.                     </xsl:element>
  649.                 </xsl:when>
  650.                 <xsl:when test="$font='sans-serif'">
  651.                     <xsl:element name="m:scr">
  652.                         <xsl:attribute name="m:val">sans-serif</xsl:attribute>
  653.                     </xsl:element>
  654.                     <xsl:element name="m:sty">
  655.                         <xsl:attribute name="m:val">p</xsl:attribute>
  656.                     </xsl:element>
  657.                 </xsl:when>
  658.                 <xsl:when test="$font='bold-sans-serif'">
  659.                     <xsl:element name="m:scr">
  660.                         <xsl:attribute name="m:val">sans-serif</xsl:attribute>
  661.                     </xsl:element>
  662.                     <xsl:element name="m:sty">
  663.                         <xsl:attribute name="m:val">b</xsl:attribute>
  664.                     </xsl:element>
  665.                 </xsl:when>
  666.                 <xsl:when test="$font='sans-serif-italic'">
  667.                     <xsl:element name="m:scr">
  668.                         <xsl:attribute name="m:val">sans-serif</xsl:attribute>
  669.                     </xsl:element>
  670.                 </xsl:when>
  671.                 <xsl:when test="$font='monospace'" />    <!-- We can't do monospace, so leave empty -->
  672.                 <xsl:when test="$font='bold'">
  673.                     <xsl:element name="m:sty">
  674.                         <xsl:attribute name="m:val">b</xsl:attribute>
  675.                     </xsl:element>
  676.                 </xsl:when>
  677.                 <xsl:when test="$font='bi'">
  678.                     <xsl:element name="m:sty">
  679.                         <xsl:attribute name="m:val">bi</xsl:attribute>
  680.                     </xsl:element>
  681.                 </xsl:when>
  682.             </xsl:choose>
  683.         </xsl:element>
  684.     </xsl:template>
  685.  
  686.     <xsl:template name="ZeroOrEmpty">
  687.         <xsl:param name="sz" />
  688.         <xsl:variable name="cchSz" select="string-length($sz)" />
  689.         <xsl:variable name="szUnit" select="substring($sz,$cchSz - 1,2)" />
  690.         <xsl:choose>
  691.             <xsl:when test="$szUnit='em' or $szUnit='pt' or $szUnit='ex' or $szUnit='in' or $szUnit='cm' or $szUnit='mm' or $szUnit='pc'">
  692.                 <xsl:if test="number(substring($sz,1,$cchSz - 2)) = 0">0</xsl:if>
  693.             </xsl:when>
  694.             <xsl:when test="substring($sz,string-length($sz),1)='%' and string(number(substring($sz,1,$sz - 1)))!='NaN'">
  695.                 <xsl:if test="number(substring($sz,1,$cchSz - 1)) = 0">0</xsl:if>
  696.             </xsl:when>
  697.             <xsl:otherwise>
  698.                 <xsl:if test="number($sz) = $sz and number($sz) = 0">0</xsl:if>
  699.             </xsl:otherwise>
  700.         </xsl:choose>        
  701.     </xsl:template>
  702.  
  703.     <!-- %%Template: match mfrac
  704.     -->
  705.     <xsl:template match="mml:mfrac">
  706.         <xsl:variable name="nlinethickness">
  707.             <xsl:call-template name="ZeroOrEmpty">
  708.                 <xsl:with-param name="sz" select="@linethickness" />
  709.             </xsl:call-template>
  710.         </xsl:variable>
  711.         <xsl:element name="m:f">
  712.             <xsl:element name="m:fPr">
  713.                 <xsl:element name="m:type">
  714.                     <xsl:attribute name="m:val">
  715.                         <xsl:choose>
  716.                             <xsl:when test="$nlinethickness = '0'">noBar</xsl:when>
  717.                             <xsl:when test="@bevelled='true'">skw</xsl:when>
  718.                             <xsl:otherwise>bar</xsl:otherwise>
  719.                         </xsl:choose>
  720.                     </xsl:attribute>
  721.                 </xsl:element>
  722.             </xsl:element>
  723.             <xsl:element name="m:num">
  724.                 <xsl:call-template name="CreateArgProp" />
  725.                 <xsl:apply-templates select="child::*[1]" />
  726.             </xsl:element>
  727.             <xsl:element name="m:den">
  728.                 <xsl:call-template name="CreateArgProp" />
  729.                 <xsl:apply-templates select="child::*[2]" />
  730.             </xsl:element>
  731.         </xsl:element>
  732.     </xsl:template>
  733.  
  734.     <!-- %%Template: match menclose msqrt
  735.     -->
  736.     <xsl:template match="mml:menclose | mml:msqrt">
  737.         <xsl:choose>
  738.             <xsl:when test="@notation='radical' or not(@notation) or @notation='' or self::mml:msqrt">
  739.                 <xsl:element name="m:rad">
  740.                     <xsl:element name="m:radPr">
  741.                         <xsl:element name="m:degHide">
  742.                             <xsl:attribute name="m:val">on</xsl:attribute>
  743.                         </xsl:element>
  744.                     </xsl:element>
  745.                     <xsl:element name="m:deg">
  746.                         <xsl:call-template name="CreateArgProp" />
  747.                     </xsl:element>
  748.                     <xsl:element name="m:e">
  749.                         <xsl:call-template name="CreateArgProp" />
  750.                         <xsl:apply-templates select="*" />
  751.                     </xsl:element>
  752.                 </xsl:element>
  753.             </xsl:when>
  754.         </xsl:choose>
  755.     </xsl:template>
  756.  
  757.     <!-- %%Template: CreateArgProp
  758.     -->
  759.     <xsl:template name="CreateArgProp">
  760.         <xsl:if test="not(count(ancestor-or-self::mml:mstyle[@scriptlevel='0' or @scriptlevel='1' or @scriptlevel='2'])=0)">
  761.             <xsl:element name="m:argPr">
  762.                 <xsl:element name="m:scrLvl">
  763.                     <xsl:attribute name="m:val">
  764.                         <xsl:value-of select="ancestor-or-self::mml:mstyle[@scriptlevel][1]/@scriptlevel" />
  765.                     </xsl:attribute>
  766.                 </xsl:element>
  767.             </xsl:element>
  768.         </xsl:if>
  769.     </xsl:template>
  770.  
  771.     <!-- %%Template: match mroot
  772.     -->
  773.     <xsl:template match="mml:mroot">
  774.         <xsl:element name="m:rad">
  775.             <xsl:element name="m:radPr">
  776.                 <xsl:element name="m:degHide">
  777.                     <xsl:attribute name="m:val">off</xsl:attribute>
  778.                 </xsl:element>
  779.             </xsl:element>
  780.             <xsl:element name="m:deg">
  781.                 <xsl:call-template name="CreateArgProp" />
  782.                 <xsl:apply-templates select="child::*[2]" />
  783.             </xsl:element>
  784.             <xsl:element name="m:e">
  785.                 <xsl:call-template name="CreateArgProp" />
  786.                 <xsl:apply-templates select="child::*[1]" />
  787.             </xsl:element>
  788.         </xsl:element>
  789.     </xsl:template>
  790.  
  791.     <!-- %%Template: match munder
  792.     -->
  793.     <xsl:template match="mml:munder">
  794.         <xsl:variable name="fNary">
  795.             <xsl:call-template name="isNary">
  796.                 <xsl:with-param name="ndCur" select="child::*[1]" />
  797.             </xsl:call-template>
  798.         </xsl:variable>
  799.         <xsl:choose>
  800.             <xsl:when test="$fNary='true'">
  801.                 <m:nary>
  802.                     <xsl:call-template name="CreateNaryProp">
  803.                         <xsl:with-param name="chr">
  804.                             <xsl:value-of select="normalize-space(child::*[1])" />
  805.                         </xsl:with-param>
  806.                         <xsl:with-param name="sMathmlType" select="'munder'" />
  807.                     </xsl:call-template>
  808.                     <m:sub>
  809.                         <xsl:call-template name="CreateArgProp" />
  810.                         <xsl:apply-templates select="child::*[2]" />
  811.                     </m:sub>
  812.                     <m:sup>
  813.                         <xsl:call-template name="CreateArgProp" />
  814.                     </m:sup>
  815.                     <m:e>
  816.                         <xsl:call-template name="CreateArgProp" />
  817.                         
  818.                         <!-- if the next sibling is an mrow, pull it in by 
  819.                             doing whatever we would have done to its children. 
  820.                             The mrow itself will be skipped, see template above. -->
  821.                         <xsl:if test="following-sibling::*[1][self::mml:mrow|self::mml:mstyle]">
  822.                             <xsl:apply-templates select="following-sibling::*[1]/*" />
  823.                         </xsl:if>
  824.                     </m:e>
  825.                 </m:nary>
  826.             </xsl:when>
  827.             <xsl:otherwise>
  828.                 <xsl:element name="m:limLow">
  829.                     <xsl:element name="m:e">
  830.                         <xsl:call-template name="CreateArgProp" />
  831.                         <xsl:apply-templates select="child::*[1]" />
  832.                     </xsl:element>
  833.                     <xsl:element name="m:lim">
  834.                         <xsl:call-template name="CreateArgProp" />
  835.                         <xsl:apply-templates select="child::*[2]" />
  836.                     </xsl:element>
  837.                 </xsl:element>
  838.             </xsl:otherwise>
  839.         </xsl:choose>
  840.     </xsl:template>
  841.  
  842.     <!-- %%Template: match mover
  843.     -->
  844.     <xsl:template match="mml:mover">
  845.         <xsl:variable name="fNary">
  846.             <xsl:call-template name="isNary">
  847.                 <xsl:with-param name="ndCur" select="child::*[1]" />
  848.             </xsl:call-template>
  849.         </xsl:variable>
  850.         <xsl:choose>
  851.             <xsl:when test="$fNary='true'">
  852.                 <m:nary>
  853.                     <xsl:call-template name="CreateNaryProp">
  854.                         <xsl:with-param name="chr">
  855.                             <xsl:value-of select="normalize-space(child::*[1])" />
  856.                         </xsl:with-param>
  857.                         <xsl:with-param name="sMathmlType" select="'mover'" />
  858.                     </xsl:call-template>
  859.                     <m:sub>
  860.                         <xsl:call-template name="CreateArgProp" />
  861.                     </m:sub>
  862.                     <m:sup>
  863.                         <xsl:call-template name="CreateArgProp" />
  864.                         <xsl:apply-templates select="child::*[2]" />
  865.                     </m:sup>
  866.                     <m:e>
  867.                         <xsl:call-template name="CreateArgProp" />
  868.                         
  869.                         <!-- if the next sibling is an mrow, pull it in by 
  870.                              doing whatever we would have done to its children. 
  871.                             The mrow itself will be skipped, see template above. -->
  872.                         <xsl:if test="following-sibling::*[1][self::mml:mrow|self::mml:mstyle]">
  873.                             <xsl:apply-templates select="following-sibling::*[1]/*" />
  874.                         </xsl:if>
  875.                     </m:e>
  876.                 </m:nary>
  877.             </xsl:when>
  878.             <xsl:otherwise>
  879.                 <xsl:element name="m:limUpp">
  880.                     <xsl:element name="m:e">
  881.                         <xsl:call-template name="CreateArgProp" />
  882.                         <xsl:apply-templates select="child::*[1]" />
  883.                     </xsl:element>
  884.                     <xsl:element name="m:lim">
  885.                         <xsl:call-template name="CreateArgProp" />
  886.                         <xsl:apply-templates select="child::*[2]" />
  887.                     </xsl:element>
  888.                 </xsl:element>
  889.             </xsl:otherwise>
  890.         </xsl:choose>
  891.     </xsl:template>
  892.  
  893.     <!-- %%Template: match munderover
  894.     -->
  895.     <xsl:template match="mml:munderover">
  896.         <xsl:variable name="fNary">
  897.             <xsl:call-template name="isNary">
  898.                 <xsl:with-param name="ndCur" select="child::*[1]" />
  899.             </xsl:call-template>
  900.         </xsl:variable>
  901.         <xsl:choose>
  902.             <xsl:when test="$fNary='true'">
  903.                 <m:nary>
  904.                     <xsl:call-template name="CreateNaryProp">
  905.                         <xsl:with-param name="chr">
  906.                             <xsl:value-of select="normalize-space(child::*[1])" />
  907.                         </xsl:with-param>
  908.                         <xsl:with-param name="sMathmlType" select="'munderover'" />
  909.                     </xsl:call-template>
  910.                     <m:sub>
  911.                         <xsl:call-template name="CreateArgProp" />
  912.                         <xsl:apply-templates select="child::*[2]" />
  913.                     </m:sub>
  914.                     <m:sup>
  915.                         <xsl:call-template name="CreateArgProp" />
  916.                         <xsl:apply-templates select="child::*[3]" />
  917.                     </m:sup>
  918.                     <m:e>
  919.                         <xsl:call-template name="CreateArgProp" />
  920.                         
  921.                         <!-- if the next sibling is an mrow, pull it in by 
  922.                              doing whatever we would have done to its children. 
  923.                             The mrow itself will be skipped, see template above. -->
  924.                         <xsl:if test="following-sibling::*[1][self::mml:mrow|self::mml:mstyle]">
  925.                             <xsl:apply-templates select="following-sibling::*[1]/*" />
  926.                         </xsl:if>
  927.                     </m:e>
  928.                 </m:nary>
  929.             </xsl:when>
  930.             <xsl:otherwise>
  931.                 <xsl:element name="m:limUpp">
  932.                     <xsl:element name="m:e">
  933.                         <xsl:call-template name="CreateArgProp" />
  934.                         <xsl:element name="m:limLow">
  935.                             <xsl:element name="m:e">
  936.                                 <xsl:call-template name="CreateArgProp" />
  937.                                 <xsl:apply-templates select="child::*[1]" />
  938.                             </xsl:element>
  939.                             <xsl:element name="m:lim">
  940.                                 <xsl:call-template name="CreateArgProp" />
  941.                                 <xsl:apply-templates select="child::*[2]" />
  942.                             </xsl:element>
  943.                         </xsl:element>
  944.                     </xsl:element>
  945.                     <xsl:element name="m:lim">
  946.                         <xsl:call-template name="CreateArgProp" />
  947.                         <xsl:apply-templates select="child::*[3]" />
  948.                     </xsl:element>
  949.                 </xsl:element>
  950.             </xsl:otherwise>
  951.         </xsl:choose>
  952.     </xsl:template>
  953.  
  954.     <!-- %%Template: match mfenced -->
  955.     <xsl:template match="mml:mfenced">
  956.         <m:d>
  957.             <xsl:call-template name="CreateDelimProp">
  958.                 <xsl:with-param name="chOpen" select="@open" />
  959.                 <xsl:with-param name="chSeperators" select="@separators" />
  960.                 <xsl:with-param name="chClose" select="@close" />
  961.             </xsl:call-template>
  962.             <xsl:for-each select="*">
  963.                 <m:e>
  964.                     <xsl:call-template name="CreateArgProp" />
  965.                     <xsl:apply-templates select="."/>
  966.                 </m:e>            
  967.             </xsl:for-each>
  968.         </m:d>
  969.     </xsl:template>
  970.  
  971.     <!-- %%Template: CreateDelimProp
  972.     
  973.         Given the characters to use as open, close and separators for 
  974.         the delim object, create the m:dPr (delim properties).         
  975.         
  976.         MathML can have any number of separators in an mfenced object, but 
  977.         OMML can only represent one separator for each d (delim) object.
  978.         So, we pick the first separator specified.         
  979.     -->
  980.     <xsl:template name="CreateDelimProp">
  981.         <xsl:param name="chOpen" />
  982.         <xsl:param name="chSeperators" />
  983.         <xsl:param name="chClose" />
  984.         
  985.         <xsl:variable name="chSep" select="substring($chSeperators, 1, 1)" />
  986.         
  987.         <!-- do we need a dPr at all? If everything's at its default value, then 
  988.             don't bother at all -->
  989.         <xsl:if test="($chOpen and not($chOpen = '(')) or
  990.                           ($chClose and not($chClose = ')')) or 
  991.                           not($chSep = '|')">
  992.             <m:dPr>
  993.                 <!-- the default for MathML and OMML is '('. -->
  994.                 <xsl:if test="$chOpen and not($chOpen = '(')">
  995.                     <m:begChr>
  996.                         <xsl:attribute name="m:val">
  997.                             <xsl:value-of select="$chOpen" />
  998.                         </xsl:attribute>
  999.                     </m:begChr>
  1000.                 </xsl:if>
  1001.                 
  1002.                 <!-- the default for MathML is ',' and for OMML is '|' -->
  1003.                 
  1004.                 <xsl:choose>            
  1005.                     <!-- matches OMML's default, don't bother to write anything out -->
  1006.                     <xsl:when test="$chSep = '|'" />
  1007.                     
  1008.                     <!-- Not specified, use MathML's default. We test against 
  1009.                     the existence of the actual attribute, not the substring -->
  1010.                     <xsl:when test="not($chSeperators)">
  1011.                         <m:sepChr m:val=',' />
  1012.                     </xsl:when>
  1013.                     
  1014.                     <xsl:otherwise>
  1015.                         <m:sepChr>
  1016.                             <xsl:attribute name="m:val">
  1017.                                 <xsl:value-of select="$chSep" />
  1018.                             </xsl:attribute>
  1019.                         </m:sepChr>                        
  1020.                     </xsl:otherwise>                    
  1021.                 </xsl:choose>
  1022.                 
  1023.                 <!-- the default for MathML and OMML is ')'. -->
  1024.                 <xsl:if test="$chClose and not($chClose = ')')">
  1025.                     <m:endChr>
  1026.                         <xsl:attribute name="m:val">
  1027.                             <xsl:value-of select="$chClose" />
  1028.                         </xsl:attribute>
  1029.                     </m:endChr>
  1030.                 </xsl:if>
  1031.             </m:dPr>
  1032.         </xsl:if>
  1033.     </xsl:template>
  1034.  
  1035.     <!-- %%Template: OutputMs
  1036.     -->
  1037.     <xsl:template name="OutputMs">
  1038.         <xsl:param name="msCur" />
  1039.         <xsl:choose>
  1040.             <xsl:when test="not($msCur/@lquote) or $msCur/@lquote=''">
  1041.                 <xsl:text>"</xsl:text>
  1042.             </xsl:when>
  1043.             <xsl:otherwise>
  1044.                 <xsl:value-of select="$msCur/@lquote" />
  1045.             </xsl:otherwise>
  1046.         </xsl:choose>
  1047.         <xsl:value-of select="normalize-space($msCur)" />
  1048.         <xsl:choose>
  1049.             <xsl:when test="not($msCur/@rquote) or $msCur/@rquote=''">
  1050.                 <xsl:text>"</xsl:text>
  1051.             </xsl:when>
  1052.             <xsl:otherwise>
  1053.                 <xsl:value-of select="$msCur/@rquote" />
  1054.             </xsl:otherwise>
  1055.         </xsl:choose>
  1056.     </xsl:template>
  1057.  
  1058.     <!-- %%Template: match msub
  1059.     -->
  1060.     <xsl:template match="mml:msub">
  1061.         <xsl:variable name="fNary">
  1062.             <xsl:call-template name="isNary">
  1063.                 <xsl:with-param name="ndCur" select="child::*[1]" />
  1064.             </xsl:call-template>
  1065.         </xsl:variable>
  1066.         <xsl:choose>
  1067.             <xsl:when test="$fNary='true'">
  1068.                 <m:nary>
  1069.                     <xsl:call-template name="CreateNaryProp">
  1070.                         <xsl:with-param name="chr">
  1071.                             <xsl:value-of select="normalize-space(child::*[1])" />
  1072.                         </xsl:with-param>
  1073.                         <xsl:with-param name="sMathmlType" select="'msub'" />
  1074.                     </xsl:call-template>
  1075.                     <m:sub>
  1076.                         <xsl:call-template name="CreateArgProp" />
  1077.                         <xsl:apply-templates select="child::*[2]" />
  1078.                     </m:sub>
  1079.                     <m:sup>
  1080.                         <xsl:call-template name="CreateArgProp" />
  1081.                     </m:sup>
  1082.                     <m:e>
  1083.                         <xsl:call-template name="CreateArgProp" />
  1084.                         
  1085.                         <!--if the next sibling is an mrow, pull it in by 
  1086.                             doing whatever we would have done to its children. 
  1087.                             The mrow itself will be skipped, see template above. -->
  1088.                         <xsl:if test="following-sibling::*[1][self::mml:mrow|self::mml:mstyle]">
  1089.                             <xsl:apply-templates select="following-sibling::*[1]/*" />
  1090.                         </xsl:if>
  1091.                     </m:e>
  1092.                 </m:nary>
  1093.             </xsl:when>
  1094.             <xsl:otherwise>
  1095.                 <m:sSub>
  1096.                     <m:e>
  1097.                         <xsl:call-template name="CreateArgProp" />
  1098.                         <xsl:apply-templates select="child::*[1]" />
  1099.                     </m:e>
  1100.                     <m:sub>
  1101.                         <xsl:call-template name="CreateArgProp" />
  1102.                         <xsl:apply-templates select="child::*[2]" />
  1103.                     </m:sub>
  1104.                 </m:sSub>
  1105.             </xsl:otherwise>
  1106.         </xsl:choose>
  1107.     </xsl:template>
  1108.  
  1109.     <!-- %%Template: match msup
  1110.     -->
  1111.     <xsl:template match="mml:msup">
  1112.         <xsl:variable name="fNary">
  1113.             <xsl:call-template name="isNary">
  1114.                 <xsl:with-param name="ndCur" select="child::*[1]" />
  1115.             </xsl:call-template>
  1116.         </xsl:variable>
  1117.         <xsl:choose>
  1118.             <xsl:when test="$fNary='true'">
  1119.                 <m:nary>
  1120.                     <xsl:call-template name="CreateNaryProp">
  1121.                         <xsl:with-param name="chr">
  1122.                             <xsl:value-of select="normalize-space(child::*[1])" />
  1123.                         </xsl:with-param>
  1124.                         <xsl:with-param name="sMathmlType" select="'msup'" />
  1125.                     </xsl:call-template>
  1126.                     <m:sub>
  1127.                         <xsl:call-template name="CreateArgProp" />
  1128.                     </m:sub>
  1129.                     <m:sup>
  1130.                         <xsl:call-template name="CreateArgProp" />
  1131.                         <xsl:apply-templates select="child::*[2]" />
  1132.                     </m:sup>
  1133.                     <m:e>
  1134.                         <xsl:call-template name="CreateArgProp" />
  1135.                         
  1136.                         <!--if the next sibling is an mrow, pull it in by 
  1137.                             doing whatever we would have done to its children. 
  1138.                             The mrow itself will be skipped, see template above. -->
  1139.                         <xsl:if test="following-sibling::*[1][self::mml:mrow|self::mml:mstyle]">
  1140.                             <xsl:apply-templates select="following-sibling::*[1]/*" />
  1141.                         </xsl:if>
  1142.                     </m:e>
  1143.                 </m:nary>
  1144.             </xsl:when>
  1145.             <xsl:otherwise>
  1146.                 <m:sSup>
  1147.                     <m:e>
  1148.                         <xsl:call-template name="CreateArgProp" />
  1149.                         <xsl:apply-templates select="child::*[1]" />
  1150.                     </m:e>
  1151.                     <m:sup>
  1152.                         <xsl:call-template name="CreateArgProp" />
  1153.                         <xsl:apply-templates select="child::*[2]" />
  1154.                     </m:sup>
  1155.                 </m:sSup>
  1156.             </xsl:otherwise>
  1157.         </xsl:choose>
  1158.     </xsl:template>
  1159.  
  1160.     <!-- %%Template: match msubsup
  1161.     -->
  1162.     <xsl:template match="mml:msubsup">
  1163.         <xsl:variable name="fNary">
  1164.             <xsl:call-template name="isNary">
  1165.                 <xsl:with-param name="ndCur" select="child::*[1]" />
  1166.             </xsl:call-template>
  1167.         </xsl:variable>
  1168.         <xsl:choose>
  1169.             <xsl:when test="$fNary='true'">
  1170.                 <m:nary>
  1171.                     <xsl:call-template name="CreateNaryProp">
  1172.                         <xsl:with-param name="chr">
  1173.                             <xsl:value-of select="normalize-space(child::*[1])" />
  1174.                         </xsl:with-param>
  1175.                         <xsl:with-param name="sMathmlType" select="'msubsup'" />
  1176.                     </xsl:call-template>
  1177.                     <m:sub>
  1178.                         <xsl:call-template name="CreateArgProp" />
  1179.                         <xsl:apply-templates select="child::*[2]" />
  1180.                     </m:sub>
  1181.                     <m:sup>
  1182.                         <xsl:call-template name="CreateArgProp" />
  1183.                         <xsl:apply-templates select="child::*[3]" />
  1184.                     </m:sup>
  1185.                     <m:e>
  1186.                         <xsl:call-template name="CreateArgProp" />
  1187.                         
  1188.                         <!--if the next sibling is an mrow, pull it in by 
  1189.                             doing whatever we would have done to its children. 
  1190.                             The mrow itself will be skipped, see template above. -->
  1191.                         <xsl:if test="following-sibling::*[1][self::mml:mrow|self::mml:mstyle]">
  1192.                             <xsl:apply-templates select="following-sibling::*[1]/*" />
  1193.                         </xsl:if>
  1194.                     </m:e>
  1195.                 </m:nary>
  1196.             </xsl:when>
  1197.             <xsl:otherwise>
  1198.                 <m:sSubSup>
  1199.                     <m:e>
  1200.                         <xsl:call-template name="CreateArgProp" />
  1201.                         <xsl:apply-templates select="child::*[1]" />
  1202.                     </m:e>
  1203.                     <m:sub>
  1204.                         <xsl:call-template name="CreateArgProp" />
  1205.                         <xsl:apply-templates select="child::*[2]" />
  1206.                     </m:sub>
  1207.                     <m:sup>
  1208.                         <xsl:call-template name="CreateArgProp" />
  1209.                         <xsl:apply-templates select="child::*[3]" />
  1210.                     </m:sup>
  1211.                 </m:sSubSup>
  1212.             </xsl:otherwise>
  1213.         </xsl:choose>
  1214.     </xsl:template>
  1215.     
  1216.     <!-- %%Template: SplitScripts 
  1217.     
  1218.         Takes an collection of nodes, and splits them
  1219.         odd and even into sup and sub scripts. Used for dealing with
  1220.         mmultiscript. 
  1221.         -->
  1222.     <xsl:template name="SplitScripts">
  1223.         <xsl:param name="ndScripts" />
  1224.         
  1225.         <m:sub>
  1226.             <xsl:call-template name="CreateArgProp" />
  1227.             <xsl:apply-templates select="$ndScripts[(position() mod 2) = 1]" />
  1228.         </m:sub>
  1229.         
  1230.         <m:sup>
  1231.             <xsl:call-template name="CreateArgProp" />
  1232.             <xsl:apply-templates select="$ndScripts[(position() mod 2) = 0]" />        
  1233.         </m:sup>
  1234.     </xsl:template>
  1235.  
  1236.     <!-- %%Template: match mmultiscripts
  1237.     
  1238.         There is some subtlety with the mml:mprescripts element. Everything that comes before 
  1239.         that is considered a script (as opposed to a pre-script), but it need not be present.
  1240.     -->
  1241.     <xsl:template match="mml:mmultiscripts">
  1242.     
  1243.         <!-- count the nodes. Everything that comes after a mml:mprescripts is considered a pre-script;
  1244.             Everything that does not have an mml:mprescript as a preceding-sibling (and is not itself 
  1245.             mml:mprescript) is a script, except for the first child which is always the base -->
  1246.         <xsl:variable name="nndPrescript" select="count(mml:mprescripts[1]/following-sibling::*)" />
  1247.         <xsl:variable name="nndScript" select="count(*[not(preceding-sibling::mml:mprescripts) and not(self::mml:mprescripts)]) - 1" />
  1248.         
  1249.         <xsl:choose>
  1250.         
  1251.             <!-- The easy case first. No prescripts, and no script ... just a base -->
  1252.             <xsl:when test="$nndPrescript <= 0 and $nndScript <= 0">
  1253.                 <xsl:apply-templates select="*[1]" />
  1254.             </xsl:when>
  1255.             
  1256.             <!-- Next, if there are no prescripts -->
  1257.             <xsl:when test="$nndPrescript <= 0">
  1258.                 <!-- we know we have some scripts or else we would have taken the earlier
  1259.                       branch. So, create a subsup and split the elements -->
  1260.                 <m:sSubSup>
  1261.                     <m:e>
  1262.                         <xsl:call-template name="CreateArgProp" />
  1263.                         <xsl:apply-templates select="child::*[1]" />
  1264.                     </m:e>
  1265.                     
  1266.                     <!-- Every child except the first is a script, split -->
  1267.                     <xsl:call-template name="SplitScripts">
  1268.                         <xsl:with-param name="ndScripts" select="*[position() > 1]" />
  1269.                     </xsl:call-template>                    
  1270.                 </m:sSubSup>
  1271.             </xsl:when>
  1272.             
  1273.             <!-- Next, if there are no scripts -->
  1274.             <xsl:when test="$nndScript <= 0">
  1275.                 <!-- we know we have some prescripts or else we would have taken the earlier
  1276.                       branch. So, create a sPre and split the elements -->
  1277.                 <m:sPre>
  1278.                     <m:e>
  1279.                         <xsl:call-template name="CreateArgProp" />
  1280.                         <xsl:apply-templates select="child::*[1]" />
  1281.                     </m:e>
  1282.                 
  1283.                     <!-- The prescripts come after the mml:mprescript and if we get here
  1284.                             we know there exists one such element -->
  1285.                     <xsl:call-template name="SplitScripts">
  1286.                         <xsl:with-param name="ndScripts" select="mml:mprescripts[1]/following-sibling::*" />
  1287.                     </xsl:call-template>
  1288.                 </m:sPre>                                                  
  1289.             </xsl:when>
  1290.             
  1291.             <!-- Finally, the case with both prescripts and scripts. Create a sPre 
  1292.                 element to house the prescripts, with a subsup element at its base. -->
  1293.             <xsl:otherwise>
  1294.                 <m:sPre>
  1295.                     <m:e>
  1296.                         <m:sSubSup>
  1297.                             <m:e>
  1298.                                 <xsl:call-template name="CreateArgProp" />
  1299.                                 <xsl:apply-templates select="child::*[1]" />
  1300.                             </m:e>
  1301.                             
  1302.                             <!-- scripts come before the mml:mprescript but after the first child, so their
  1303.                                  positions will be 2, 3, ... ($nndScript + 1) -->
  1304.                             <xsl:call-template name="SplitScripts">
  1305.                                 <xsl:with-param name="ndScripts" select="*[(position() > 1) and (position() <= ($nndScript + 1))]" />
  1306.                             </xsl:call-template>                    
  1307.                         </m:sSubSup>
  1308.                     </m:e>
  1309.                 
  1310.                     <!-- The prescripts come after the mml:mprescript and if we get here
  1311.                             we know there exists one such element -->
  1312.                     <xsl:call-template name="SplitScripts">
  1313.                         <xsl:with-param name="ndScripts" select="mml:mprescripts[1]/following-sibling::*" />
  1314.                     </xsl:call-template>
  1315.                 </m:sPre>
  1316.             </xsl:otherwise>
  1317.         </xsl:choose>
  1318.     </xsl:template>
  1319.     
  1320.     
  1321.     <xsl:template match="mml:mtable">
  1322.         <xsl:variable name="cMaxElmtsInRow">
  1323.             <xsl:call-template name="CountMaxElmtsInRow">
  1324.                 <xsl:with-param name="ndCur" select="*[1]" />
  1325.                 <xsl:with-param name="cMaxElmtsInRow" select="0" />
  1326.             </xsl:call-template>
  1327.         </xsl:variable>
  1328.         <m:m>
  1329.             <m:mPr>
  1330.                 <m:baseJc m:val="center" />
  1331.                 <m:plcHide m:val="on" />
  1332.                 <m:mcs>
  1333.                     <m:mc>
  1334.                         <m:mcPr>
  1335.                             <m:count>
  1336.                                 <xsl:attribute name="m:val">
  1337.                                     <xsl:value-of select="$cMaxElmtsInRow" />
  1338.                                 </xsl:attribute>
  1339.                             </m:count>
  1340.                             <m:mcJc m:val="center" />
  1341.                         </m:mcPr>
  1342.                     </m:mc>
  1343.                 </m:mcs>                
  1344.             </m:mPr>
  1345.             <xsl:for-each select="*">
  1346.                 <xsl:choose>
  1347.                     <xsl:when test="self::mml:mtr or self::mml:mlabeledtr">
  1348.                         <m:mr>
  1349.                             <xsl:choose>
  1350.                                 <xsl:when test="self::mml:mtr">
  1351.                                     <xsl:for-each select="*">
  1352.                                         <m:e>
  1353.                                             <xsl:apply-templates select="." />
  1354.                                         </m:e>
  1355.                                     </xsl:for-each>
  1356.                                     <xsl:call-template name="CreateEmptyElmt">
  1357.                                         <xsl:with-param name="cEmptyMtd" select="$cMaxElmtsInRow - count(*)" />
  1358.                                     </xsl:call-template>
  1359.                                 </xsl:when>
  1360.                                 <xsl:otherwise>
  1361.                                     <xsl:for-each select="*[position() > 1]">
  1362.                                         <m:e>
  1363.                                             <xsl:apply-templates select="." />
  1364.                                         </m:e>
  1365.                                     </xsl:for-each>
  1366.                                     <xsl:call-template name="CreateEmptyElmt">
  1367.                                         <xsl:with-param name="cEmptyMtd" select="$cMaxElmtsInRow - (count(*) - 1)" />
  1368.                                     </xsl:call-template>
  1369.                                 </xsl:otherwise>
  1370.                             </xsl:choose>
  1371.                         </m:mr>
  1372.                     </xsl:when>
  1373.                     <xsl:otherwise>
  1374.                         <m:mr>
  1375.                             <m:e>
  1376.                                 <xsl:apply-templates select="." />
  1377.                             </m:e>
  1378.                             <xsl:call-template name="CreateEmptyElmt">
  1379.                                 <xsl:with-param name="cEmptyMtd" select="$cMaxElmtsInRow - 1" />
  1380.                             </xsl:call-template>
  1381.                         </m:mr>
  1382.                     </xsl:otherwise>
  1383.                 </xsl:choose>
  1384.             </xsl:for-each>
  1385.         </m:m>
  1386.     </xsl:template>
  1387.     <xsl:template match="m:mtd">
  1388.         <xsl:apply-templates select="*" />
  1389.     </xsl:template>
  1390.     <xsl:template name="CreateEmptyElmt">
  1391.         <xsl:param name="cEmptyMtd" />
  1392.         <xsl:if test="$cEmptyMtd > 0">
  1393.             <m:e></m:e>
  1394.             <xsl:call-template name="CreateEmptyElmt">
  1395.                 <xsl:with-param name="cEmptyMtd" select="$cEmptyMtd - 1" />
  1396.             </xsl:call-template>
  1397.         </xsl:if>
  1398.     </xsl:template>
  1399.     <xsl:template name="CountMaxElmtsInRow">
  1400.         <xsl:param name="ndCur" />
  1401.         <xsl:param name="cMaxElmtsInRow" select="0" />
  1402.         <xsl:choose>
  1403.             <xsl:when test="not($ndCur)">
  1404.                 <xsl:value-of select="$cMaxElmtsInRow" />
  1405.             </xsl:when>
  1406.             <xsl:otherwise>
  1407.                 <xsl:call-template name="CountMaxElmtsInRow">
  1408.                     <xsl:with-param name="ndCur" select="$ndCur/following-sibling::*[1]" />
  1409.                     <xsl:with-param name="cMaxElmtsInRow">
  1410.                         <xsl:choose>
  1411.                             <xsl:when test="local-name($ndCur) = 'mlabeledtr' and 
  1412.                                             namespace-uri($ndCur) = 'http://www.w3.org/1998/Math/MathML'">
  1413.                                 <xsl:choose>
  1414.                                     <xsl:when test="(count($ndCur/*) - 1) > $cMaxElmtsInRow">
  1415.                                         <xsl:value-of select="count($ndCur/*) - 1" />
  1416.                                     </xsl:when>
  1417.                                     <xsl:otherwise>
  1418.                                         <xsl:value-of select="$cMaxElmtsInRow" />
  1419.                                     </xsl:otherwise>
  1420.                                 </xsl:choose>
  1421.                             </xsl:when>
  1422.                             <xsl:when test="local-name($ndCur) = 'mtr' and 
  1423.                                             namespace-uri($ndCur) = 'http://www.w3.org/1998/Math/MathML'">
  1424.                                 <xsl:choose>
  1425.                                     <xsl:when test="count($ndCur/*) > $cMaxElmtsInRow">
  1426.                                         <xsl:value-of select="count($ndCur/*)" />
  1427.                                     </xsl:when>
  1428.                                     <xsl:otherwise>
  1429.                                         <xsl:value-of select="$cMaxElmtsInRow" />
  1430.                                     </xsl:otherwise>
  1431.                                 </xsl:choose>
  1432.                             </xsl:when>
  1433.                             <xsl:otherwise>
  1434.                                 <xsl:choose>
  1435.                                     <xsl:when test="1 > $cMaxElmtsInRow">
  1436.                                         <xsl:value-of select="1" />
  1437.                                     </xsl:when>
  1438.                                     <xsl:otherwise>
  1439.                                         <xsl:value-of select="$cMaxElmtsInRow" />
  1440.                                     </xsl:otherwise>
  1441.                                 </xsl:choose>
  1442.                             </xsl:otherwise>
  1443.                         </xsl:choose>
  1444.                     </xsl:with-param>
  1445.                 </xsl:call-template>
  1446.             </xsl:otherwise>
  1447.         </xsl:choose>
  1448.     </xsl:template>
  1449.     <xsl:template match="mml:mglyph">
  1450.         <xsl:call-template name="CreateMglyph" />
  1451.     </xsl:template>
  1452.     <xsl:template match="mml:mi[child::mml:mglyph] | 
  1453.                          mml:mn[child::mml:mglyph] | 
  1454.                          mml:mo[child::mml:mglyph] | 
  1455.                          mml:ms[child::mml:mglyph] | 
  1456.                          mml:mtext[child::mml:mglyph]">
  1457.         <xsl:element name="m:r">
  1458.             <xsl:call-template name="CreateRunProp">
  1459.                 <xsl:with-param name="mathvariant" select="@mathvariant" />
  1460.                 <xsl:with-param name="fontstyle" select="@fontstyle" />
  1461.                 <xsl:with-param name="fontweight" select="@fontweight" />
  1462.                 <xsl:with-param name="mathcolor" select="@mathcolor" />
  1463.                 <xsl:with-param name="mathsize" select="@mathsize" />
  1464.                 <xsl:with-param name="color" select="@color" />
  1465.                 <xsl:with-param name="fontsize" select="@fontsize" />
  1466.                 <xsl:with-param name="ndCur" select="." />
  1467.             </xsl:call-template>
  1468.             <xsl:element name="m:t">
  1469.                 <xsl:call-template name="OutputText">
  1470.                     <xsl:with-param name="sInput">
  1471.                         <xsl:choose>
  1472.                             <xsl:when test="self::mml:ms">
  1473.                                 <xsl:call-template name="OutputMs">
  1474.                                     <xsl:with-param name="msCur" select="." />
  1475.                                 </xsl:call-template>
  1476.                             </xsl:when>
  1477.                             <xsl:otherwise>
  1478.                                 <xsl:value-of select="normalize-space(.)" />
  1479.                             </xsl:otherwise>
  1480.                         </xsl:choose>
  1481.                     </xsl:with-param>
  1482.                 </xsl:call-template>
  1483.             </xsl:element>
  1484.         </xsl:element>
  1485.         <xsl:for-each select="child::mml:mglyph">
  1486.             <xsl:call-template name="CreateMglyph">
  1487.                 <xsl:with-param name="ndCur" select="." />
  1488.             </xsl:call-template>
  1489.         </xsl:for-each>
  1490.     </xsl:template>
  1491.     <xsl:template name="FGlyphIndexOk">
  1492.         <xsl:param name="index" />
  1493.         <xsl:if test="$index != ''">
  1494.             <xsl:choose>
  1495.                 <xsl:when test="string(number(string(floor($index)))) = 'NaN'" />
  1496.                 <xsl:when test="number($index) < 32 and not(number($index) = 9 or number($index) = 10 or number($index) = 13)" />
  1497.                 <xsl:when test="number($index) = 65534 or number($index) = 65535" />
  1498.                 <xsl:otherwise>1</xsl:otherwise>
  1499.             </xsl:choose>
  1500.         </xsl:if>
  1501.     </xsl:template>
  1502.     <xsl:template name="CreateMglyph">
  1503.         <xsl:param name="ndCur" />
  1504.         <m:r>
  1505.             <xsl:call-template name="CreateRunProp">
  1506.                 <xsl:with-param name="mathvariant">
  1507.                     <xsl:choose>
  1508.                         <xsl:when test="(not(@mathvariant) or @mathvariant='') and ../@mathvariant!=''">
  1509.                             <xsl:value-of select="../@mathvariant" />
  1510.                         </xsl:when>
  1511.                         <xsl:otherwise>
  1512.                             <xsl:value-of select="@mathvariant" />
  1513.                         </xsl:otherwise>
  1514.                     </xsl:choose>
  1515.                 </xsl:with-param>
  1516.                 <xsl:with-param name="fontstyle">
  1517.                     <xsl:choose>
  1518.                         <xsl:when test="(not(@fontstyle) or @fontstyle='') and ../@fontstyle!=''">
  1519.                             <xsl:value-of select="../@fontstyle" />
  1520.                         </xsl:when>
  1521.                         <xsl:otherwise>
  1522.                             <xsl:value-of select="@fontstyle" />
  1523.                         </xsl:otherwise>
  1524.                     </xsl:choose>
  1525.                 </xsl:with-param>
  1526.                 <xsl:with-param name="fontweight">
  1527.                     <xsl:choose>
  1528.                         <xsl:when test="(not(@fontweight) or @fontweight='') and ../@fontweight!=''">
  1529.                             <xsl:value-of select="../@fontweight" />
  1530.                         </xsl:when>
  1531.                         <xsl:otherwise>
  1532.                             <xsl:value-of select="@fontweight" />
  1533.                         </xsl:otherwise>
  1534.                     </xsl:choose>
  1535.                 </xsl:with-param>
  1536.                 <xsl:with-param name="mathcolor">
  1537.                     <xsl:choose>
  1538.                         <xsl:when test="(not(@mathcolor) or @mathcolor='') and ../@mathcolor!=''">
  1539.                             <xsl:value-of select="../@mathcolor" />
  1540.                         </xsl:when>
  1541.                         <xsl:otherwise>
  1542.                             <xsl:value-of select="@mathcolor" />
  1543.                         </xsl:otherwise>
  1544.                     </xsl:choose>
  1545.                 </xsl:with-param>
  1546.                 <xsl:with-param name="mathsize">
  1547.                     <xsl:choose>
  1548.                         <xsl:when test="(not(@mathsize) or @mathsize='') and ../@mathsize!=''">
  1549.                             <xsl:value-of select="../@mathsize" />
  1550.                         </xsl:when>
  1551.                         <xsl:otherwise>
  1552.                             <xsl:value-of select="@mathsize" />
  1553.                         </xsl:otherwise>
  1554.                     </xsl:choose>
  1555.                 </xsl:with-param>
  1556.                 <xsl:with-param name="color">
  1557.                     <xsl:choose>
  1558.                         <xsl:when test="(not(@color) or @color='') and ../@color!=''">
  1559.                             <xsl:value-of select="../@color" />
  1560.                         </xsl:when>
  1561.                         <xsl:otherwise>
  1562.                             <xsl:value-of select="@color" />
  1563.                         </xsl:otherwise>
  1564.                     </xsl:choose>
  1565.                 </xsl:with-param>
  1566.                 <xsl:with-param name="fontsize">
  1567.                     <xsl:choose>
  1568.                         <xsl:when test="(not(@fontsize) or @fontsize='') and ../@fontsize!=''">
  1569.                             <xsl:value-of select="../@fontsize" />
  1570.                         </xsl:when>
  1571.                         <xsl:otherwise>
  1572.                             <xsl:value-of select="@fontsize" />
  1573.                         </xsl:otherwise>
  1574.                     </xsl:choose>
  1575.                 </xsl:with-param>
  1576.                 <xsl:with-param name="ndCur" select="." />
  1577.                 <xsl:with-param name="fontfamily" select="@fontfamily" />
  1578.             </xsl:call-template>
  1579.             <xsl:variable name="shouldGlyphUseIndex">
  1580.                 <xsl:call-template name="FGlyphIndexOk">
  1581.                     <xsl:with-param name="index" select="@index" />
  1582.                 </xsl:call-template>
  1583.             </xsl:variable>
  1584.             <xsl:choose>
  1585.                 <xsl:when test="not($shouldGlyphUseIndex = '1')">
  1586.                     <m:t>
  1587.                         <xsl:value-of select="@alt" />
  1588.                     </m:t>
  1589.                 </xsl:when>
  1590.                 <xsl:otherwise>
  1591.                     <xsl:variable name="nHexIndex">
  1592.                         <xsl:call-template name="ConvertDecToHex">
  1593.                             <xsl:with-param name="index" select="@index" />
  1594.                         </xsl:call-template>
  1595.                     </xsl:variable>
  1596.                     <m:t>
  1597.                         <xsl:text disable-output-escaping="yes">&#x</xsl:text>
  1598.                         <xsl:value-of select="$nHexIndex" />
  1599.                         <xsl:text>;</xsl:text>
  1600.                     </m:t>
  1601.                 </xsl:otherwise>
  1602.             </xsl:choose>
  1603.         </m:r>
  1604.     </xsl:template>
  1605.     <xsl:template name="ConvertDecToHex">
  1606.         <xsl:param name="index" />
  1607.         <xsl:if test="$index > 0">
  1608.             <xsl:call-template name="ConvertDecToHex">
  1609.                 <xsl:with-param name="index" select="floor($index div 16)" />
  1610.             </xsl:call-template>
  1611.             <xsl:choose>
  1612.                 <xsl:when test="$index mod 16 < 10">
  1613.                     <xsl:value-of select="$index mod 16" />
  1614.                 </xsl:when>
  1615.                 <xsl:otherwise>
  1616.                     <xsl:choose>
  1617.                         <xsl:when test="$index mod 16 = 10">A</xsl:when>
  1618.                         <xsl:when test="$index mod 16 = 11">B</xsl:when>
  1619.                         <xsl:when test="$index mod 16 = 12">C</xsl:when>
  1620.                         <xsl:when test="$index mod 16 = 13">D</xsl:when>
  1621.                         <xsl:when test="$index mod 16 = 14">E</xsl:when>
  1622.                         <xsl:when test="$index mod 16 = 15">F</xsl:when>
  1623.                         <xsl:otherwise>A</xsl:otherwise>
  1624.                     </xsl:choose>
  1625.                 </xsl:otherwise>
  1626.             </xsl:choose>
  1627.         </xsl:if>
  1628.     </xsl:template>
  1629.     <xsl:template match="mml:mphantom">
  1630.         <m:phant>
  1631.             <m:phantPr>
  1632.                 <m:width m:val="on" />
  1633.                 <m:asc m:val="on" />
  1634.                 <m:dec m:val="on" />
  1635.             </m:phantPr>
  1636.             <m:e>
  1637.                 <xsl:apply-templates select="*" />
  1638.             </m:e>
  1639.         </m:phant>
  1640.     </xsl:template>
  1641.     <xsl:template name="isNaryOper">
  1642.         <xsl:param name="sNdCur" />
  1643.         <xsl:value-of select="($sNdCur = '∫' or $sNdCur = '∬' or $sNdCur = '∭' or $sNdCur = '∮' or $sNdCur = '∯' or $sNdCur = '∰' or $sNdCur = '∲' or $sNdCur = '∳' or $sNdCur = '∱' or $sNdCur = '∩' or $sNdCur = '∪' or $sNdCur = '∏' or $sNdCur = '∐' or $sNdCur = '∑')" />
  1644.     </xsl:template>
  1645.     <xsl:template name="isNary">
  1646.         <xsl:param name="ndCur" />
  1647.         <xsl:variable name="sNdCur">
  1648.             <xsl:value-of select="normalize-space($ndCur)" />
  1649.         </xsl:variable>
  1650.         <xsl:variable name="fNaryOper">
  1651.             <xsl:call-template name="isNaryOper">
  1652.                 <xsl:with-param name="sNdCur" select="$sNdCur" />
  1653.             </xsl:call-template>
  1654.         </xsl:variable>
  1655.         <xsl:choose>
  1656.             <xsl:when test="local-name($ndCur/descendant-or-self::*[last()])    = 'mo'         and
  1657.                             not($ndCur/descendant-or-self::*[not(self::mml:mo or 
  1658.                                                                  self::mml:mstyle or 
  1659.                                                                  self::mml:mrow)])             and
  1660.                             namespace-uri($ndCur/descendant-or-self::*[last()]) = 'http://www.w3.org/1998/Math/MathML'   and
  1661.                             $fNaryOper = 'true'">
  1662.                 <xsl:value-of select="true()" />
  1663.             </xsl:when>
  1664.             <xsl:otherwise>
  1665.                 <xsl:value-of select="false()" />
  1666.             </xsl:otherwise>
  1667.         </xsl:choose>
  1668.     </xsl:template>
  1669.     <xsl:template name="CreateNaryProp">
  1670.         <xsl:param name="chr" />
  1671.         <xsl:param name="sMathmlType" />
  1672.         <m:naryPr>
  1673.             <m:chr>
  1674.                 <xsl:attribute name="m:val">
  1675.                     <xsl:value-of select="$chr" />
  1676.                 </xsl:attribute>
  1677.             </m:chr>
  1678.             <m:limLoc>
  1679.                 <xsl:attribute name="m:val">
  1680.                     <xsl:choose>
  1681.                         <xsl:when test="$sMathmlType='munder' or 
  1682.                                     $sMathmlType='mover' or 
  1683.                                     $sMathmlType='munderover'">
  1684.                             <xsl:text>undOvr</xsl:text>
  1685.                         </xsl:when>
  1686.                         <xsl:when test="$sMathmlType='msub' or
  1687.                                     $sMathmlType='msup' or
  1688.                                     $sMathmlType='msubsup'">
  1689.                             <xsl:text>subSup</xsl:text>
  1690.                         </xsl:when>
  1691.                     </xsl:choose>
  1692.                 </xsl:attribute>
  1693.             </m:limLoc>
  1694.             <m:grow>
  1695.                 <xsl:attribute name="m:val">
  1696.                     <xsl:value-of select="'on'" />
  1697.                 </xsl:attribute>
  1698.             </m:grow>
  1699.             <m:subHide>
  1700.                 <xsl:attribute name="m:val">
  1701.                     <xsl:choose>
  1702.                         <xsl:when test="$sMathmlType='mover' or
  1703.                                         $sMathmlType='msup'">
  1704.                             <xsl:text>on</xsl:text>
  1705.                         </xsl:when>
  1706.                         <xsl:otherwise>
  1707.                             <xsl:text>off</xsl:text>
  1708.                         </xsl:otherwise>
  1709.                     </xsl:choose>
  1710.                 </xsl:attribute>
  1711.             </m:subHide>
  1712.             <m:supHide>
  1713.                 <xsl:attribute name="m:val">
  1714.                     <xsl:choose>
  1715.                         <xsl:when test="$sMathmlType='munder' or
  1716.                                         $sMathmlType='msub'">
  1717.                             <xsl:text>on</xsl:text>
  1718.                         </xsl:when>
  1719.                         <xsl:otherwise>
  1720.                             <xsl:text>off</xsl:text>
  1721.                         </xsl:otherwise>
  1722.                     </xsl:choose>
  1723.                 </xsl:attribute>
  1724.             </m:supHide>
  1725.         </m:naryPr>
  1726.     </xsl:template>
  1727. </xsl:stylesheet>